<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper" style="height: 900px;">
    <div class="content" style="height: 900px;">
        <div class="location">房屋管理</div>
        <{include file= "Room/nav.html"}>
        <div class="topic">添加房屋</div>
        <div class="form-box border0 border-box">
            <form action="<{u($smarty.const.ACTION_NAME)}>" class="ui-form" method="post" id="addManagerForm">

                <input type="hidden"  name="rid" value="<{$obj.rid}>" />

                <div class="ui-form-item">
                    <label class="ui-label">名称：</label>
                    <input type="text" class="ui-text" name="roomName" value="<{$obj.roomName}>" required/>
                </div>
                <div class="ui-form-item">
                    <label class="ui-label">房屋面积：</label>
                    <input type="number" class="ui-text" name="area" value="<{$obj.area}>" required/> 平方
                </div>
                <div class="ui-form-item">
                    <label class="ui-label">床型：</label>
                    <select class="ui-select" name="bed">
                    <{html_options options=$bedKv selected=$obj.bed}>
                    </select>

                </div>
                <div class="ui-form-item">
                    <label class="ui-label">宜住人数：</label>
                    <input type="number" class="ui-text" name="bed" placeholder="2" value="<{$obj.people}>" required/>
                </div>
                <div class="ui-form-item">
                    <label class="ui-label">房屋头图：</label>
                    <span class="picture_box picture_150 " id="listPic" >
                        <div class="a-imgBox" id="imgBox" <{if $obj.listPic}> style="display:block;"<{else}>style="display:none;"<{/if}> >
                            <input type="hidden" name="listPic" value="<{$preUploadUrl}><{$obj.listPic}>">
                            <a href="javascript:void(0);" class="a-close" onclick="deleteListPic()"></a>
                            <img src="<{$preUploadUrl}><{$obj.listPic}>" width="150" height="130" />
                        </div>
                        <div>
                            <a href="javascript:;" class="a-upload">
                                <input type="file" name="file"  >
                            </a>
                            <i>上传图片</i>
                            <i>150*130</i>
                        </div>
                    </span>
                </div>


        <div class="ui-form-item2 uploader" style="min-height: 157px">
            <label class="ui-label">房屋图集:</label>
            <div style="width: calc(100% - 200px);display: inline-block;">
                <{foreach from=split(',',$obj.album) item=img}>
                    <{if strlen($img)>1}>
                    <span class="picture_box picture_150">
                        <div class="a-imgBox"   style="display:block;">
                            <a href="javascript:void(0);" class="a-close" onclick="removeElement(this)"></a>
                            <img src="<{$preUploadUrl}><{$img}>" width="150" height="130" />
                            <input type="hidden" name="album[]" value="<{$img}>" />
                        </div>
                    </span>
                    <{/if}>
                <{/foreach}>

                    <span class="picture_box picture_150 " id="addImg" style="position: absolute;">
                        <div>
                            <a href="javascript:;" class="a-upload">
                                <input type="file" name="file"  >
                            </a>
                            <i>上传图片</i>
                            <i>150*130</i>
                        </div>
                    </span>
            </div>
        </div>

        <div class="ui-form-item">
            <label class="ui-label">备注说明：</label>
            <textarea  class="ui-text" name="desc"  style="width: 300px;height:150px;"><{$obj.desc}></textarea>
        </div>

                <div class="integral_btn-group">
                    <input type="submit" value="提交" class="ui-button"/>
                </div>

            </form>
        </div>
    </div>
</div>
</body>
<{include file="Public/foot.html" }>

<script>
    //删除图片
    function deleteListPic() {
        $('#imgBox').hide();
        $('.uptxt').text('上传图片');
        $('#listPic').val('');
    }

    (function ($) {
        'use strict';
        $.fn.uploader = function () {
            return this.each(function () {
                var $this = $(this);
                var $img = $this.find('img');
                var $file = $this.find('input[type=file]');
                var $hidden = $this.find('input[type=hidden]');
                var $txt = $this.find('i.uptxt');
                $file.AjaxFileUpload({
                    action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_ROOM_ALBUM',
                    onSubmit: function () {
                        $txt.text('上传中');
                    },
                    onComplete: function (filename, response) {
                        if(parseInt(response.id)>0){
                            $txt.text("上传成功");
                            newImg(response.msg);
                        }else{
                            $txt.text(response.msg);
                        }
                    }
                });
            });
        }
    })(jQuery);
    $('#addImg').uploader();


    (function ($) {
        'use strict';
        $.fn.uploader = function () {
            return this.each(function () {
                var $this = $(this);
                var $img = $this.find('img');
                var $file = $this.find('input[type=file]');
                var $hidden = $this.find('input[type=hidden]');
                var $txt = $this.find('i.uptxt');
                var $imgBox = $this.find('div[id=imgBox]');
                $file.AjaxFileUpload({
                    action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_ROOM_LIST',
                    onSubmit: function () {
                        $txt.text('上传中');
                    },
                    onComplete: function (filename, response) {
                        if(parseInt(response.id)>0){
                            $txt.text("上传成功");
                            $hidden.attr('value', response.msg);
                            $img.attr("src",response.msg);
                            $imgBox.css('display','block');
                        }else{
                            $txt.text(response.msg);
                        }

                    }
                });
            });
        }
    })(jQuery);

    $('#listPic').uploader();

    function removeElement(obj){
        $(obj).parents('.picture_150').remove();
    }

    function newImg(src){
        $img=$('<span class="picture_box picture_150"><div class="a-imgBox"  style="display:block;"><a href="javascript:void(0);" class="a-close" onclick="removeElement(this)"></a><img src="<{$preUploadUrl}><{$img}>" width="150" height="130" /> <input type="hidden" name="album[]" value="" /></div></span>');
        $('#addImg').before($img);
        $img.find('input[type=hidden]').val(src);
        $img.find('img').attr('src',src);
    }



</script>